package com.tjtt.tdm.system.action;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.acegisecurity.providers.encoding.Md5PasswordEncoder;
import org.acegisecurity.providers.encoding.PasswordEncoder;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.struts2.ServletActionContext;

import com.tjtt.common.utils.HttpUtil;
import com.tjtt.common.utils.MD5;
import com.tjtt.common.utils.StringUtil;
import com.tjtt.gwm.service.DbService;
import com.tjtt.tdm.base.BaseAction;
import com.tjtt.tdm.base.PageResult;
import com.tjtt.tdm.base.ParamBean;
import com.tjtt.tdm.exception.DaoException;
import com.tjtt.tdm.exception.ServiceException;
import com.tjtt.tdm.exception.XMLException;
import com.tjtt.tdm.system.bean.ConfigInfo;
import com.tjtt.tdm.system.bean.Organization;
import com.tjtt.tdm.system.bean.SysCerify;
import com.tjtt.tdm.system.bean.UserRole;
import com.tjtt.tdm.system.bean.Users;
import com.tjtt.tdm.system.service.ConfigService;
import com.tjtt.tdm.system.service.LogService;
import com.tjtt.tdm.system.service.UserRoleService;
import com.tjtt.tdm.system.service.UserService;

public class UserAction extends BaseAction {
	private DbService dbService;
	private static final long serialVersionUID = 1L;
	private static final Log log = LogFactory.getLog(UserAction.class);
	private UserService userService;
	private UserRoleService userRoleService;
	private LogService logService;
	private ConfigService configService;
	private ConfigInfo info;
	private Users users;
	private UserRole userole;
	private Long userId;
	private Long roleid;
	
	/**分页变量*/
	private String page;
	private String rows;
	private String sidx;
	private String sord;
	
	private Long orgId;
	private String oldPsw;
	/**
	 * 角色组
	 */
	private String roleIdStr;
	private String loginname;
	private String username;
	private String active;
	private String sex;
	private String fixedPhone;
	private String lockFlag;
	private String mobile;
	private String email;
	private String userdesc;
	private Long securityClass;
	private String companyTel;
	private String address;
	//private Long  posName;
	private String jobName;
	private String orgNameLabel;
	private String userIds;
	private Long posId;
	private String psw;
	
	private Timestamp entryDate;   //入职时间
	private Long workYears;  //工作年限
	private String yourMajor; //所学专业
	private Long age; //年龄
	private String xueliname; //学历
	private Long xueliid;   //学历Id
	private String zhichengname; //职称
	private Long zhichengid;   //职称Id
	private String zhiwuname; //职务
	private Long zhiwuid;   //职务id
	private String shemidjname; //职务
	private Long shemidjid;   //职务id
	/** 标记用户查询当前是查询原数据还是查询已经选择的数据 */
	private int searchFlag;
	
	/**标记用户修改个人信息是否成功*/
	private int successFlag;
	
	private File uploadImg;
	private String uploadImgContentType;
	private String uploadImgFileName;
	
	private File uploadSign;
	private String uploadSignContentType;
	private String uploadSignFileName;
	
	private File uploadStamp;
	private String uploadStampContentType;
	private String uploadStampFileName;
	
	
	
	private HSSFSheet reportDataSheet;
	private SysCerify sysCerify;
	private Organization organization;
	/**
	 * 删除用户，不真实删除数据，只修改删除标记
	 * @return
	 * @throws IOException
	 * @throws ServiceException
	 */
	
	
	
//	public String delUserExec() throws IOException,ServiceException{
//		setContentType();
//		PrintWriter out = getResponse().getWriter();
//	  	try {
//	  		String ids=getRequest().getParameter("ids");
//	  		if(ids !=null&&! ids.isEmpty()){
//			String idss[] = ids.split(",");
//				for(String id : idss){
//					Users users = userService.getUsers(Long.parseLong(id));
//					users.setDelFlag("2");
//					//把删除的用户的组织id全改成1，组织才能删除。
//					Organization organization = new Organization();
//					organization.setOrgId(1l);
//					users.setOrganization(organization);
//					
//					userService.saveUsers(users,null);
//					//删除用户角色关联
//					userRoleService.delUserRole(Long.parseLong(id));
//				}
//	  		}
//			out.print("{\"ajaxResult\":\"success\"}");
//			logService.saveLogInfo(this.getLogBase(), "系统管理", "用户管理", "成功删除一条用户记录",3);
//			return null;
//	  	} catch (Exception e) {
//			e.printStackTrace();
//			out.print("{\"ajaxResult\":\"error\"}");
//			logService.saveLogInfo(this.getLogBase(), "系统管理", "用户管理", "删除用户失败",3);
//			return null;
//		}
//	}
	public String delUserExec() throws IOException,ServiceException{
		setContentType();
		PrintWriter out = getResponse().getWriter();
	  	try {
	  		String ids=getRequest().getParameter("ids");
	  		if(ids !=null&&! ids.isEmpty()){
			String idss[] = ids.split(",");
				for(String id : idss){
					String sql="delete from sys_users t where t.userid='"+id+"'";
					
					dbService.exeSql(sql);
					
//					Users users = userService.getUsers(Long.parseLong(id));
//					users.setDelFlag("2");
					//把删除的用户的组织id全改成1，组织才能删除。
//					Organization organization = new Organization();
//					organization.setOrgId(1l);
//					users.setOrganization(organization);
//					
//					userService.saveUsers(users,null);
					//删除用户角色关联
					userRoleService.delUserRole(Long.parseLong(id));
				}
	  		}
			out.print("{\"ajaxResult\":\"success\"}");
			logService.saveLogInfo(this.getLogBase(), "系统管理", "用户管理", "成功删除一条用户记录",3);
			return null;
	  	} catch (Exception e) {
			e.printStackTrace();
			out.print("{\"ajaxResult\":\"error\"}");
			logService.saveLogInfo(this.getLogBase(), "系统管理", "用户管理", "删除用户失败",3);
			return null;
		}
	}
	/**
	 * 验证用户登录名称是否存在
	 * @return
	 * @throws IOException
	 * @throws ServiceException
	 * @author Xuxinyue
	 * */
	public void judgeLoginNameExec() throws Exception{
		setContentType();
		PrintWriter out = getResponse().getWriter();
		HashMap<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("delFlag","1");
		paramMap.put("loginname",loginname);
		if(userService.getTotalCount(paramMap).intValue() > 0){
			log.error(getText("user.loginname.duplicate"));
			out.print("false");
			//throw new ServiceException(getText("user.loginname.duplicate"));		
		}else{
			out.print("true");
		}
	}
	/**
	 * 图片上传
	 * @return
	 * @throws Exception
	 * @author Xuxinyue
	 * */
	private Users uploadPicExec(Users users) throws Exception{
		String contentType = this.getRequest().getContentType();
		String maxSize = getRequest().getSession().getServletContext().getInitParameter("maxSize");
		if(contentType==null || !contentType.startsWith("multipart/form-data"))  //没有文件提交
		{	
		}else{
			String url = this.getRequest().getSession().getAttribute("SYS_FILEPATH")  + "/Users/" + System.currentTimeMillis()+  "/picManage";
			users.setImgPath(url);
			File file = new File(url);
			if ( ! (file.exists())  &&   ! (file.isDirectory()))  {
                 boolean  creadok  =  file.mkdirs();
                 if (creadok)  {
                    System.out.println( " ok:创建文件夹成功！ " );
                } else  {
                    System.out.println( " err:创建文件夹失败！ " );                    
                } 
            } 
			String address;
			FileOutputStream fos;
			FileInputStream fis;
			byte[] buffer = new byte[1024]; 
			int len = 0; 
			if(uploadImg!=null && !"".equals(uploadImg)){		
				if(uploadImg.length()>0)  //大于30M 30M= 30*1024*1024  
				{
					address = url + "/" + System.currentTimeMillis()+this.getUploadImgFileName();
					fos = new FileOutputStream(address);
					fis = new FileInputStream(uploadImg);	
					while ((len = fis.read(buffer)) > 0) 
					{ 
						fos.write(buffer, 0, len);
					} 
					fos.flush();
					fos.close();
					fis.close();
					users.setImgAddress(address);
				}else if(uploadImg.length() == 0){
					getRequest().setAttribute("message", "文件大小为空，不能上传！");
				}else{
					getRequest().setAttribute("message", "文件大小超过限制！");
				}
				
			}
			if(uploadSign!=null && !"".equals(uploadSign)){
				//if(uploadSign.length()>0 && uploadSign.length() <= Integer.parseInt(maxSize))  //大于30M 30M= 30*1024*1024  
				if(uploadSign.length()>0)  //大于30M 30M= 30*1024*1024  
				{
					address = url + "/" + System.currentTimeMillis()+this.getUploadSignFileName();
					fos = new FileOutputStream(address);
					fis = new FileInputStream(uploadSign);
					while ((len = fis.read(buffer)) > 0) 
					{ 
						fos.write(buffer, 0, len);
					} 
					fos.flush();
					fos.close();
					fis.close();
					users.setSignAddress(address);
				}else if(uploadSign.length() == 0){
					getRequest().setAttribute("message", "文件大小为空，不能上传！");
				}else{
					getRequest().setAttribute("message", "文件大小超过限制！");
				}
				
			}
			if(uploadStamp!=null && !"".equals(uploadStamp)){
				if(uploadStamp.length()>0 && uploadStamp.length() <= Integer.parseInt(maxSize))  //大于30M 30M= 30*1024*1024  
				{
					address = url + "/" + System.currentTimeMillis()+this.getUploadStampFileName();
					fos = new FileOutputStream(address);
					fis = new FileInputStream(uploadStamp);
					while ((len = fis.read(buffer)) > 0) 
					{ 
						fos.write(buffer, 0, len);
					} 
					fos.flush();
					fos.close();
					fis.close();
					users.setStampAddress(address);
				}else if(uploadStamp.length() == 0){
					getRequest().setAttribute("message", "文件大小为空，不能上传！");
				}else{
					getRequest().setAttribute("message", "文件大小超过限制！");
				}
				
			}
			
		}
		return users;
	}
	/**
	 * 保存用户信息
	 * @return
	 * @throws IOException
	 * @throws ServiceException
	 */
	/**
	 * @return
	 * @throws Exception
	 */
	public void saveUserExec() throws Exception {
		try {
				HttpServletResponse response = ServletActionContext.getResponse();
				PrintWriter out = response.getWriter(); 
				PasswordEncoder md5pass = new Md5PasswordEncoder();
				HashMap<String, Object> paramMap = new HashMap<String, Object>();
				paramMap.put("delFlag","1");
				Long organationId=Long.parseLong(getRequest().getParameter("orgId"));
				long totalCount = userService.getTotalCount(paramMap);
				paramMap.put("loginname",loginname);
//				if(userService.getTotalCount(paramMap).intValue() > 0){
//					log.error(getText("user.loginname.duplicate"));
//					throw new ServiceException(getText("user.loginname.duplicate"));
//				}
				//图片上传
				users = uploadPicExec(users);
				Organization organization = new Organization();
				organization.setOrgId(organationId);
				users.setDelFlag("1");
				users.setLockFlag("0");
				users.setLoginname(loginname);
				//users.setPosName(2l);// 给了个默认值
				users.setOrganization(organization);	
				ConfigInfo info = this.configService.getConfigInfoById(null);
				String pwd = info.getSysPwd();
				users.setPsw(md5pass.encodePassword(pwd,null));
				users.setXueliid(xueliid);
				users.setXueliname(xueliname);
				users.setZhiwuid(zhiwuid);
				users.setZhiwuname(zhiwuname);
				users.setZhichengid(zhichengid);
				users.setZhichengname(zhichengname);
				users.setShemidjid(shemidjid);
				users.setShemidjname(shemidjname);
				userService.saveUsers(users,roleIdStr);
				//getRequest().setAttribute("message", "新建成功！");
				out.print("{\"result\":\"success\"}");
				logService.saveLogInfo(this.getLogBase(), "系统管理", "用户管理", "成功添加一条用户记录",3);
		}catch (Exception e) {
			e.printStackTrace();
			logService.saveLogInfo(this.getLogBase(), "系统管理", "用户管理", "添加用户失败",3);
		}
	}
	
	  /**
	   * 查看用户信息\
	   * @return String
	   * @author 宿馨月 
	   * @date 2012-9-6 下午02:11:56
	   */
	public String searchUserByIdExec(){
		  Long userId = Long.parseLong(getRequest().getParameter("testId"));
		  users=userService.findUsersById(userId);
		  return SUCCESS;
			  
	}
	  /**
	   * 跳转到用户信息修改页面
	   * @return String
	   * @author 宿馨月 
	   * @date 2012-9-6 下午02:11:56
	   */
	public String toUpdateUserExec(){
		Long userId = Long.parseLong(getRequest().getParameter("testId"));
		  users=userService.findUsersById(userId);
		  SimpleDateFormat df = new SimpleDateFormat("yyyy");//定义格式，不显示毫秒 yyyy-MM-dd 
			Timestamp now = new Timestamp(System.currentTimeMillis());//获取系统当前时间
			String str = df.format(now);
			getRequest().setAttribute("str", str);
		  return SUCCESS;  
	}
	/**
	 * 跳转到用户信息增加页面
	 * @return String
	 * @author 宿馨月 
	 * @date 2012-9-6 下午02:11:56
	 */
	public String goAddUserExec(){
		Long orgId = Long.parseLong(getRequest().getParameter("orgId"));
		organization=userService.findOrganationByorgId(orgId);
		SimpleDateFormat df = new SimpleDateFormat("yyyy");//定义格式，不显示毫秒 yyyy-MM-dd 
		Timestamp now = new Timestamp(System.currentTimeMillis());//获取系统当前时间
		String str = df.format(now);
		getRequest().setAttribute("str", str);
		getRequest().setAttribute("orgId", orgId);
		return SUCCESS;  
	}
	/**
	 * 修改用户信息
	 * @return
	 * @throws IOException
	 * @throws ServiceException
	 */
	public void updateUserExec() throws IOException, ServiceException{
		try {
			HttpServletResponse response = ServletActionContext.getResponse();
			PrintWriter out = response.getWriter(); 
			users=userService.findUsersById(userId);
			Organization organization = new Organization();
			organization.setOrgId(orgId);
			users.setDelFlag("1"); 
			users.setOrganization(organization);
			users.setUsername(username);
			users.setSex(Long.parseLong(sex));
			users.setCompanyTel(companyTel);
			users.setFixedPhone(fixedPhone);
			users.setMobile(mobile);
			users.setEmail(email);
			users.setAddress(address);
			users.setEntryDate(entryDate);
			users.setWorkYears(workYears);
			users.setYourMajor(yourMajor);
			users.setAge(age);
			users.setXueliid(xueliid);
			users.setXueliname(xueliname);
			users.setZhiwuid(zhiwuid);
			users.setZhiwuname(zhiwuname);
			users.setZhichengid(zhichengid);
			users.setZhichengname(zhichengname);
			users.setShemidjid(shemidjid);
			users.setShemidjname(shemidjname);
			 
			users.setActive(Long.parseLong(active));
			//users.setPosName(posName);
			users.setJobName(jobName);
			users.setSecurityClass(securityClass);
			users.setUserdesc(userdesc);
			//图片上传
			users = uploadPicExec(users);
			
			userService.updateUsers(users,roleIdStr);
			//JSONObject jsonObject = new JSONObject();
			//jsonObject.put("success",true);
			//out.write(jsonObject.toString());
			//getRequest().setAttribute("message", "修改成功！");
			out.print("{\"result\":\"success\"}");
			
			logService.saveLogInfo(this.getLogBase(), "系统管理", "用户管理", "成功修改一条用户记录",3);
		}catch (Exception e) {
			e.printStackTrace();
			logService.saveLogInfo(this.getLogBase(), "系统管理", "用户管理", "修改用户失败",3);
		}
		//return null;
	}
	
	/**
	 * 编辑个人信息
	 * @return
	 * @throws IOException
	 * @throws ServiceException String
	 * @author 曹晓芳
	 * @date Aug 31, 2012 10:04:38 AM
	 */
	public String updateUserInfoExec() throws IOException, ServiceException{
		try{
			setContentType();
			PrintWriter out = getResponse().getWriter();
			//String sex = getRequest().getParameter("sex");
			successFlag = 1;
			users=userService.findUsersById(userId);
			if(null != psw && psw.length()!=0){
				//Users oldUser = this.userService.getUsers(users.getUserid());
				//判断用户输入的旧密码是否与数据库中输入的密码一致
				PasswordEncoder md5pass = new Md5PasswordEncoder();
				String md5OldPsw = md5pass.encodePassword(oldPsw,null);
				if(!users.getPsw().equals(md5OldPsw)){
					successFlag = 1;
					getRequest().setAttribute("message", "旧密码错误！");
					return "userInfo";
				}
				users.setPsw(md5pass.encodePassword(psw,null));
				users.setPwdEditTime(new Date());	
				//this.userService.updatePswEditTime(users.getUserid());
			}
			users.setUsername(username);
			users.setCompanyTel(companyTel);
			users.setMobile(mobile);
			users.setEmail(email);
			//性别 职务 
			users.setSex(Long.parseLong(sex));
			//users.setPosName(posName);
			//图片上传
			Users updateusers = uploadPicExec(users);
			userService.updateUserInfo(updateusers);
			getRequest().setAttribute("message", "修改成功！");
			out.print("{\"ajaxResult\":\"success\"}");
			logService.saveLogInfo(this.getLogBase(), "系统管理", "个人信息管理", "成功修改个人信息",3);
			return "userInfo";
		}catch(Exception e) {
			e.printStackTrace();
			getRequest().setAttribute("message", "修改失败！");
			logService.saveLogInfo(this.getLogBase(), "系统管理", "个人信息管理", "修改个人信息失败",3);
			return ERROR;
		}
	}
	/**
	 * 跳转到个人信息修改页面
	 * @return
	 * @throws IOException
	 * @throws ServiceException String
	 * @author 曹晓芳
	 * @date Aug 31, 2012 10:42:21 AM
	 */
	public String toUserInfoExec() throws IOException, ServiceException{
		setContentType();
		users = this.userService.getUsers(this.getUser().getUserid());
		return "userInfo";
	}	
	/**
	 * 密码重置
	 * @return
	 * @throws IOException
	 * @throws ServiceException
	 */
	public String resetUserPwdExec() throws IOException, ServiceException{
		setContentType();
		PasswordEncoder md5pass = new Md5PasswordEncoder();
		PrintWriter out = getResponse().getWriter();
		try{
			info = this.configService.getConfigInfoById(null);
			String pwd = info.getSysPwd();
			Users users = userService.getUsers(userId);
			users.setPsw(md5pass.encodePassword(pwd,null));
			userService.saveUsers(users,null);
			this.userService.updatePswEditTime(users.getUserid());
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("success",true);
			out.write(jsonObject.toString());
			logService.saveLogInfo(this.getLogBase(), "系统管理", "用户管理", "成功重置密码",3);
			return null;
		}catch (Exception e) {
			e.printStackTrace();
			logService.saveLogInfo(this.getLogBase(), "系统管理", "用户管理", "重置密码失败",3);
			return null;
		}
	}
	/**
	 * 带查询条件的 点击左侧数查询右侧列表
	 * @return
	 * @throws IOException
	 * @throws ServiceException
	 */
	public String findUserGridSearchByOrgIdExec() throws IOException, ServiceException{
		try {
			PrintWriter out = getResponse().getWriter();
			Map<String, String> filterMap = getPagerMap();
			//取出页面中的查询条件
			String loginname = getRequest().getParameter("loginname");
			if(loginname != null && !"".equals(loginname)){
				loginname = StringUtil.encodingUrl(loginname);
				loginname = StringUtil.escapeString(loginname);
			}
			String username =getRequest().getParameter("username");
			if(username != null && !"".equals(username)){
				username = StringUtil.encodingUrl(username);
				username = StringUtil.escapeString(username);
			}
			String activeLabel =getRequest().getParameter("activeLabel");
			if(activeLabel != null && !"".equals(activeLabel)){
				activeLabel = StringUtil.encodingUrl(activeLabel);
				activeLabel = StringUtil.escapeString(activeLabel);
			}
			
			String lockFlagLabel =getRequest().getParameter("lockFlagLabel");
			if(lockFlagLabel != null && !"".equals(lockFlagLabel)){
				lockFlagLabel = StringUtil.encodingUrl(lockFlagLabel);
				lockFlagLabel = StringUtil.escapeString(lockFlagLabel);
			}
			
			String orgId =getRequest().getParameter("orgId");
			if(orgId != null && !"".equals(orgId)){
				orgId = StringUtil.encodingUrl(orgId);
				orgId = StringUtil.escapeString(orgId);
			}
			
			//将查询条件保存到Map里
			filterMap.put("loginname", loginname);
			filterMap.put("username", username);
			filterMap.put("activeLabel", activeLabel);
			filterMap.put("lockFlagLabel", lockFlagLabel);
			filterMap.put("orgId", orgId);
			String[] viewArray = {"userid","loginname","username","sexLabel:[{'1':'男','0':'女'}]","jobName","org_id","activeLabel:[{'0':'外出试验','1':'有效'}]","lockFlagLabel:[{'0':'未锁定','1':'锁定'}]","organization.orgName"};
			//查询所有的数据
			PageResult pageresult =  userService.queryUserList2(filterMap);
			String returnStr = getColumnJson(pageresult,viewArray);
			out.print(returnStr);	
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	/**
	 * 查询用户信息
	 * @return
	 * @throws IOException
	 * @throws ServiceException
	 */
	public String searchUsersExec() throws IOException, ServiceException{
		setContentType();
		PrintWriter out = getResponse().getWriter();	
		Map filterMap = getPagerMap();
		//String orgIds = getRequest().getParameter("id");
		String orgIds = getRequest().getParameter("orgId");
		filterMap.put("orgId", orgIds);		
		String[] viewArray = {"userid","loginname","username","sexLabel:[{'1':'男','0':'女'}]","jobName","org_id","activeLabel:[{'0':'外出试验','1':'有效'}]","lockFlagLabel:[{'0':'未锁定','1':'锁定'}]","organization.orgName"};
		//查询所有的数据
		PageResult pageresult =  userService.queryUserList(filterMap);
		String returnStr = getColumnJson(pageresult,viewArray);
		out.print(returnStr);	
		return null;
	}
	/**
	 * 根据角色的id查询用户
	 * @return
	 * @throws IOException
	 * @throws ServiceException
	 */
	public String searchUsersByRoleIdExec()throws IOException, ServiceException{
		setContentType();
		PrintWriter out = getResponse().getWriter();
		List<Users> users=userService.findUsersByRoleId(roleid);
		HashMap<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("delFlag","1");
		long totalCount = users.size();
		JSONObject result = new JSONObject();
		JSONArray usersJson = JSONArray.fromObject(users);
		result.put("records", totalCount);
		result.put("rows", usersJson);
		result.put("page", page); //总页数);
		result.put("total", (totalCount +  Integer.parseInt(rows) - 1) / Integer.parseInt( rows));
		out.write(result.toString());
		return null;
	}
	
	/*
	 * 取得页面传过来的列表参数
	 */
	public Map getPagerMap(){
		String pages = page + "";
		String row = rows + "";
		if(pages==null) pages ="1";
		if(sidx==null) sidx ="id";
		if(row==null) row = "10";
		if(sord==null) sord ="asc";
		Map filterMap = new HashMap();//存储参数的map
		filterMap.put("page", Integer.parseInt(pages));
		filterMap.put("rows", Integer.parseInt(row));
		filterMap.put("sidx", sidx);
		filterMap.put("sord", sord);
		return filterMap;
	}

	/**
	 * 得到往页面传的josn对象
	 * String
	 * 2011-4-26下午09:06:10
	 * author：李数
	 */
	public String getColumnJson(PageResult result,String[] viewArray){
		int rowsInt= Integer.parseInt(rows);
		int totalRows = result.getRowCount(); //所有的行数
		int totalPages = (totalRows + rowsInt - 1) / rowsInt; //总页数
		List rowAll = result.getData();   //查询出的所有记录
		JSONObject obj = new JSONObject();
		obj.put("page", ""+page);
		obj.put("total",totalPages);
		obj.put("records",""+totalRows);
		JSONArray lineitemArray = new JSONArray(); 
		Iterator it = rowAll.iterator();
		while (it.hasNext()) { 
			Object[] objlist = (Object[]) it.next();
			lineitemArray.add(getColumnValue(objlist,viewArray));
		} 
		obj.put("rows", lineitemArray);
		return obj.toString();
	}

	public JSONObject getColumnValue(Object[] objlist,String[] viewArray) {
		JSONObject objlineitem = new JSONObject();	
        for (int i=0;i<viewArray.length;i++)
        { 
        	if(!StringUtil.isEmpty(viewArray[i])){
        		if(objlist[i] != null ){
        			if(viewArray[i].indexOf(":")>0){
            			String realfieldName = viewArray[i].substring(0,viewArray[i].indexOf(":"));
            			String jsonStr = viewArray[i].substring(viewArray[i].indexOf(":")+1);
    	        		JSONArray json = JSONArray.fromObject(jsonStr);
    	        		JSONObject job = json.getJSONObject(0);
    	        		if(job.containsKey(objlist[i].toString())){
    	        			 String realvalue = job.getString(objlist[i].toString());
    		        		 if(realvalue!=null){
    		        			 objlineitem.put(realfieldName, realvalue.toString());
    		        		 }
    	        		}else{
    	        			 objlineitem.put(realfieldName, objlist[i].toString());
    	        		}
            		}else{
            			 if(objlist[i]!=null){
            				 objlineitem.put(viewArray[i], objlist[i].toString());
            			 } else {
            				 objlineitem.put(viewArray[i], "");
            				}
            		}
	        	}else {
					 objlineitem.put(viewArray[i], "");
				}
        	}
        }
		return objlineitem;
	}
	
	/**
	 * 根据组织结构的Id查询用户
	 * @return
	 * @throws IOException
	 * @throws ServiceException
	 * @throws DaoException 
	 */
	public String searchUsesByOrgIdExec()throws IOException, ServiceException, DaoException{
		setContentType();
		PrintWriter out = getResponse().getWriter();	
		Map filterMap = getPagerMap();
		String orgIds = getRequest().getParameter("id");
		filterMap.put("orgId", orgIds);		
		String[] viewArray = {"userid","loginname","username","sexLabel:[{'1':'男','0':'女'}]","jobName","org_id","activeLabel:[{'0':'外出试验','1':'有效'}]","lockFlagLabel:[{'0':'未锁定','1':'锁定'}]","organization.orgName"};
		//查询所有的数据
		PageResult pageresult =  userService.queryUserList(filterMap);
		String returnStr = getColumnJson(pageresult,viewArray);
		out.print(returnStr);	
		return null;
	}
	public String searchUsesByOrgId2Exec()throws IOException, ServiceException, DaoException{
		setContentType();
		PrintWriter out = getResponse().getWriter();
		/*HashMap<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("delFlag","1");
		int start = rows * ( page - 1); 
		int limit = 15;
		List<Users> users=userService.findUsersByOrgId(start,limit,orgId);*/	
		Map filterMap = getPagerMap();
		String orgIds = getRequest().getParameter("id");
		filterMap.put("orgId", orgIds);		
		String[] viewArray = {"userid","loginname","username","sexLabel:[{'1':'男','0':'女'}]","jobName","org_id","activeLabel:[{'0':'外出试验','1':'有效'}]","lockFlagLabel:[{'0':'未锁定','1':'锁定'}]","organization.orgName"};
		//查询所有的数据
		PageResult pageresult =  userService.queryUserList(filterMap);
		String returnStr = getColumnJson(pageresult,viewArray);
		out.print(returnStr);	
		/*long totalCount = users.size();
		JSONObject result = new JSONObject();
		JSONArray usersJson = JSONArray.fromObject(users);
		result.put("records", totalCount);
		result.put("rows", usersJson);
		result.put("page", page); //总页数);
		result.put("total", (totalCount + rows - 1) / rows);
		out.write(result.toString());*/
		return null;
	}
	/**
	 * 密码修改
	 * @return
	 * @throws IOException
	 * @throws ServiceException
	 */
	public String changePswExec() throws IOException, ServiceException{
		setContentType();
		PrintWriter out = getResponse().getWriter();
		JSONObject result = new JSONObject();
		Users user = this.getUser();
		PasswordEncoder md5pass = new Md5PasswordEncoder();
		String md5OldPsw = md5pass.encodePassword(this.oldPsw,null);
		if(!user.getPsw().equals(md5OldPsw)){
			result.put("success","false");
			out.write(result.toString());
			return null;
		}
		user.setPsw(md5pass.encodePassword(this.users.getPsw(),null));
		this.userService.saveUsers(user,null);
		this.userService.updatePswEditTime(users.getUserid());
		this.getHttpSession().setAttribute("TDM_USER",user);
		result.put("success", "true");
		out.write(result.toString());
		return null;
		
	}
	
	
	/**
	 * 用户查询
	 * 
	 * @return null
	 * @throws IOException
	 * @throws ServiceException
	 * @throws DaoException 
	 */
	public String searchUserExec(){
		setContentType();
		PrintWriter out;
		try {
			out = getResponse().getWriter();
			JSONObject result = new JSONObject();
			String userDeptId = getRequest().getParameter("userDeptId");
			String allusersId =  getRequest().getParameter("allusersId");
			String roleId =  getRequest().getParameter("flowrole");
			
			if(searchFlag==0){
				HashMap<String, Object> paramMap = new HashMap<String, Object>();
				String hql = "1=1";
				if (null != users && StringUtils.isNotEmpty(users.getUsername())) {
					String userName = StringUtil.encodingUrl(users.getUsername());
					hql += " and entity.username like '%"+userName.trim()+"%'";
				}
				if (null != users && StringUtils.isNotEmpty(users.getLoginname())) {
					String loginname = StringUtil.encodingUrl(users.getLoginname());
					hql += " and entity.loginname like '%"+loginname.trim()+"%'";
				}
				if( !"null".equals(userIds) && StringUtils.isNotEmpty(userIds)){
					hql += " and entity.userid not in("+userIds+")";
				}
				
				if( !"null".equals(allusersId) && StringUtils.isNotEmpty(allusersId)){
					if(allusersId.startsWith(",")){
						allusersId = allusersId.substring(1);
					}
					if(allusersId.endsWith(",")){
						allusersId = allusersId.substring(0,allusersId.length()-1);
					}
					hql += " and entity.userid  in("+allusersId+")";
				}
				
				
				if(null != roleId&&!roleId.equals("")){
					hql += " and entity.userid in(select userid from com.tjtt.tdm.system.bean.UserRole where roleid in  ("+roleId+"))";
				}
				
				if(null != users && StringUtils.isNotEmpty(users.getOrganization().getOrgName())){
					
					String orgName = StringUtil.encodingUrl(users.getOrganization().getOrgName());
					hql += " and entity.organization.orgId in(select orgId from com.tjtt.tdm.system.bean.Organization where orgName like '%"+orgName.trim()+"%')";
				}
				if(!StringUtil.isEmpty(userDeptId)){
					hql += " and entity.organization.orgId = "+userDeptId+")";
				}
				
				
				hql += " and entity.delFlag = '1'";
				
				if(null != users && null!=users.getOrganization().getOrgId()){
					String orgChildSql ="select wmsys.wm_concat(distinct t.org_id) from sys_organization t start with t.org_id = "+users.getOrganization().getOrgId()+" connect by prior t.org_id = t.org_parent_id ";
					List orgChildList = userService.getDatabySql(orgChildSql);
					if(null!=orgChildList&&orgChildList.size()>0&&null!=orgChildList.get(0)){
						String allOrgIds = orgChildList.get(0).toString();
						
						hql += " and entity.organization.orgId in ("+allOrgIds+") ";
					}
					
				}
				
				int start =  Integer.parseInt(rows) * (  Integer.parseInt(page) - 1); //开始的记录
				long totalCount  = this.userService.getTotalCountByWhereHql(hql);
				
				List<Users> user = this.userService.getListByHql(start, Integer.parseInt(rows), sidx, sord,hql);
				
				result.put("rowCount", totalCount);
				result.put("data", user);
				result.put("page", page); //总页数);
				result.put("total", (totalCount + Integer.parseInt(rows) - 1) /  Integer.parseInt(rows));
				out.write(result.toString());
			}else{
				HashMap<String, Object> paramMap = new HashMap<String, Object>();
				paramMap.put("delFlag","1");
				List<Users> list = new ArrayList<Users>();
				if(!"null".equals(userIds) && StringUtils.isNotEmpty(userIds)){
					String[] ids = userIds.split(",");
					Long[] roleIds = new Long[ids.length];
					for(int i=0;i<ids.length;i++){
						String idss = ids[i].trim();
						roleIds[i] = Long.valueOf(idss);
					}
					paramMap.put("userid", roleIds);
					list = this.userService.findUsers(paramMap, 0, 0, 0, sidx, sord);
				}
				result.put("data", list);
				out.write(result.toString());
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
	/**
	 * 解锁
	 * @return
	 * @throws IOException
	 * @throws ServiceException
	 */
	public String unLockExec() throws IOException, ServiceException{
		setContentType();
		PrintWriter out = getResponse().getWriter();
		try{
			/*批量删除
			String ids=getRequest().getParameter("ids");
			if(ids !=null&&! ids.isEmpty()){
				String idss[] = ids.split(",");
					for(String id : idss){
						Users users = userService.getUsers(Long.parseLong(id));
						users.setLockFlag("0");
						users.setPwdFailCount(0L);
						users.setLockTime(null);
						userService.saveUsers(users,null);
					}
		  		}*/
			Users users = userService.getUsers(userId);
			users.setLockFlag("0");
			users.setPwdFailCount(0L);
			users.setLockTime(null);
			userService.saveUsers(users,null);
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("success",true);
			out.write(jsonObject.toString());
			logService.saveLogInfo(this.getLogBase(), "系统管理", "用户管理", "解锁成功",3);
			return null;
		}catch (Exception e) {
			e.printStackTrace();
			logService.saveLogInfo(this.getLogBase(), "系统管理", "用户管理", "解锁失败",3);
			return null;
		}
	}
	/**
	 * 角色管理查看用户信息
	 * @return
	 * @throws IOException
	 * @throws ServiceException
	 */
	public String findUsersExec() throws IOException, ServiceException{
		setContentType();
		PrintWriter out = getResponse().getWriter();
		HashMap<String, Object> paramMap = new HashMap<String, Object>();
		long totalCount=0;
		List<Users> users=null;
		if (null != roleid && roleid > 0) {			
			totalCount = userService.findUsersByRoleId(roleid).size();
			users = userService.searchUsersByRoleId(roleid,this.getStart(),this.getLimit());
		}else{
			paramMap.put("delFlag","1");
			totalCount = userService.getTotalCount(paramMap);
			users = userService.findUsers(paramMap, totalCount, this.getStart(), this.getLimit(), this.getSort(), this.getDir());
		}
		JSONObject result = new JSONObject();
		JSONArray usersJson = JSONArray.fromObject(users);
		result.put("count", totalCount);
		result.put("users", usersJson);
		out.write(result.toString());
		return null;
	}	
	/**
	 * 新的角色管理查看用户信息
	 * @return
	 * @throws IOException
	 * @throws ServiceException
	 */
	public String findUsersNExec() throws IOException, ServiceException{
		setContentType();
		PrintWriter out = getResponse().getWriter();
		HashMap<String, Object> paramMap = new HashMap<String, Object>();
		long totalCount=0;
		int start =  Integer.parseInt(rows) * (  Integer.parseInt(page) - 1);
		List<Users> users=null;
		if (null != roleid && roleid > 0) {			
			totalCount = userService.findUsersByRoleId(roleid).size();
			users = userService.searchUsersByRoleId(roleid,start, Integer.parseInt(rows));
		}else{
			paramMap.put("delFlag","1");
			totalCount = userService.getTotalCount(paramMap);
			users = userService.findUsers(paramMap, totalCount, this.getStart(), this.getLimit(), this.getSort(), this.getDir());
		}
		JSONObject result = new JSONObject();
		JSONArray usersJson = JSONArray.fromObject(users);
		result.put("count", totalCount);
		result.put("users", usersJson);
		result.put("page", page); //总页数);
		result.put("total", (totalCount +  Integer.parseInt(rows) - 1) /  Integer.parseInt(rows));
		out.write(result.toString());
		return null;
	}
		
	 /**
     * 导出excel文档
     * @return
     * @throws ServiceException
     * @throws XMLException
     * @throws IOException
     */
    public String exportExcelExec() throws Exception {
    	try {
        	HashMap<String, Object> paramMap = new HashMap<String, Object>();
        	if (StringUtils.isNotEmpty(loginname)) {
    			ParamBean p = new ParamBean();
    			p.setParam("loginname");
    			p.setExpression(" like ");
    			p.setValue("%" + loginname + "%");
    			paramMap.put("loginname", p);
    		}
    		if (StringUtils.isNotEmpty(username)) {
    			username = StringUtil.encodingUrl(username);
    			ParamBean p = new ParamBean();
    			p.setParam("username");
    			p.setExpression(" like ");
    			p.setValue("%" + username + "%");
    			paramMap.put("username", p);
    		}
    		if (StringUtils.isNotEmpty(active)) {
    			paramMap.put("active", Long.parseLong(active));
    		}
    		if (StringUtils.isNotEmpty(lockFlag)) {
    			paramMap.put("lockFlag", lockFlag);
    		}
    		if (null != orgId && orgId > 0) {
    			paramMap.put("organization.orgId",orgId);
    		}
    		ParamBean p = new ParamBean();
    		p.setParam("userid");
    		p.setExpression("<>");
    		p.setValue(Long.parseLong("4"));
    		paramMap.put("userid", p);
    		
    		paramMap.put("delFlag","1");
    		String url = this.getRequest().getSession().getAttribute("SYS_FILEPATH") + "\\downloadExcel";
			File file = new File(url);
			if ( ! (file.exists())  &&   ! (file.isDirectory()))  {
                 boolean  creadok  =  file.mkdirs();
                 if (creadok)  {
                    System.out.println( " ok:创建文件夹成功！ " );
                } else  {
                    System.out.println( " err:创建文件夹失败！ " );                    
                } 
            } 
    		String address = url + "/" + System.currentTimeMillis()+".xls";
    		//String[] headers = {"编号","用户名","姓名","性别","所属组织","职务","单位电话", "家庭电话","移动电话","电子邮件","办公地址","用户状态","锁定状态"};
    		String[] headers = {"编号","用户名","姓名","性别","所属组织","单位电话", "家庭电话","移动电话","电子邮件","办公地址","用户状态","锁定状态"};
        	ExportExcel<Users> ex = new ExportExcel<Users>();
        	long totalCount = userService.getTotalCount(paramMap);
        	List<Users> dataset = userService.findUsers(paramMap, totalCount, this.getStart(), this.getLimit(), this.getSort(), this.getDir());
        	OutputStream out = new FileOutputStream(address);
        	ex.exportExcel("用户管理列表",headers, dataset, out,"yyyy-MM-dd");
        	out.close();
            // JOptionPane.showMessageDialog(null, "导出成功!");
        	download(address);
            logService.saveLogInfo(this.getLogBase(), "系统管理", "用户管理", "导出成功",3);
        	return null;
		} catch (Exception e) {
			e.printStackTrace();
			logService.saveLogInfo(this.getLogBase(), "系统管理", "用户管理", "导出失败",3);
			return null;
		}

    }
    //下载导出的Excel
    public void download(String downloadPath) throws UnsupportedEncodingException
	{
		File downloadFile = new File(downloadPath);
		if(downloadFile.exists())
		{
			getResponse().setHeader("Server","www.digitaltest.cn");
			getResponse().setHeader("Content-Type", "application/octet-stream");
			getResponse().setHeader("Content-Length", String.valueOf(downloadFile.length()));
			getResponse().setHeader("Content-Disposition", "attachment; filename=\"" + java.net.URLEncoder.encode("用户信息","UTF-8") + ".xls\"");	
			try {
				OutputStream downloadStream=getResponse().getOutputStream();
				FileInputStream fin=new FileInputStream(downloadFile);
				byte[] b=new byte[1024];				
				int length=fin.read(b);
				while(length>0)
				{
					downloadStream.write(b,0,length);
					length=fin.read(b);
				}
				downloadStream.flush();
				fin.close();	
			} catch (IOException e) {
				e.printStackTrace();
			}			
		}
		else
		{
			getResponse().setHeader("Content-Type", "text/html; charset=UTF-8");
			try {
				getResponse().getWriter().write("<html>");
				getResponse().getWriter().write("<head>");
				getResponse().getWriter().write("</head>");
				getResponse().getWriter().write("<body>");
				getResponse().getWriter().write("文件没有找到<br>");
				getResponse().getWriter().write("<a href='#' onclick='javascript:history.back(-1)'>返回</a>");
				getResponse().getWriter().write("</body>");
				getResponse().getWriter().write("</html>");
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
    
    public void searchUsers(){
    	try{
    		Map<String, String> filterMap = getPagerMap();	
    		String username;
    		username = getRequest().getParameter("username");
			if(username !=null && !"".equals(username)){
				username = StringUtil.encodingUrl(username);
				username = StringUtil.escapeString(username);
			}
			String orgName = getRequest().getParameter("orgName");
			//String testdate = getRequest().getParameter("testdate");
			//将查询条件保存到Map里//hgshshgshsfhsfghfshsh	
			filterMap.put("username", username);
			filterMap.put("orgName", orgName);
    		
			String[] viewArray = {"userid","username","loginname","organization.orgName"};
			String returnStr = "";
			
			PageResult result = userService.queryUser(filterMap);
			returnStr = getColumnJson(result, viewArray);
			
			setContentType();
			PrintWriter out = getResponse().getWriter();
			System.out.println(returnStr);
			out.print(returnStr);
    	}catch (Exception e) {
    		e.printStackTrace();

		}
    }
    @SuppressWarnings("unused")
	public void updatePwd()throws ServiceException{
		try {
			PrintWriter out = getResponse().getWriter();
			String userid = ServletActionContext.getRequest().getSession().getAttribute("TDM_USER_ID").toString();
			Users user=userService.findUsersById(Long.parseLong(userid));
			user.setPsw(new MD5().getMD5ofStr(psw).toLowerCase());
//			userService.updateUserInfo(user);
			user.setPwdEditTime(new Date());
			userService.editUserInfo(user);
			out.print("{\"result\":\"success\"}");
			getRequest().setAttribute("message", "修改成功!");
			logService.saveLogInfo(this.getLogBase(), "修改密码", "修改密码", "修改密码修改成功",3);
		} catch (Exception e) {
			getRequest().setAttribute("message", "修改失败");
			logService.saveLogInfo(this.getLogBase(), "修改密码", "修改密码", "修改密码失败",3);
		}
	}
    /**
     * 验证旧密码是否输入正确updateUserInfo
     * @throws IOException void
     * @author 谈泊麟
     * @date 2013-3-18 上午10:25:31
     */
    public void findPwd() throws IOException {
		PrintWriter out = getResponse().getWriter();
		try {	
			String oldPwd =  StringUtil.escapeString(StringUtil.encodingUrl(getRequest().getParameter("oldPwd")));
			String userid = ServletActionContext.getRequest().getSession().getAttribute("TDM_USER_ID").toString();
			Users user=userService.findUsersById(Long.parseLong(userid));
			String Pwd= user.getPsw();
			if(Pwd.equals(new MD5().getMD5ofStr(oldPwd).toLowerCase())){
				out.print("{\"result\":\"success\"}");			
			}else{
				out.print("{\"result\":\"false\"}");
				}		
		} catch (Exception e) {
			e.printStackTrace();
			out.print("{\"result\":\"false\"}");
		}
	}
    /**
	 * 查询用户名是否存在
	 * @throws Exception void
	 * @author 张海娜
	 * @date 2013-2-21 下午01:56:10
	 */
	public void findUsersByloginNameExec() throws IOException {
		PrintWriter out = getResponse().getWriter();
		try {	
			String loginname = StringUtil.encodingUrl(getRequest().getParameter("loginname"));
			String old = StringUtil.encodingUrl(getRequest().getParameter("old"));
			if(loginname.equals(old)){
				out.print("{\"result\":\"success\"}");				
			}else{
				Users user = userService.findUsersByloginName(loginname);
				if (user == null) {
					out.print("{\"result\":\"success\"}");
				} else {
					out.print("{\"result\":\"false\"}");
				}
			}			
		} catch (Exception e) {
			e.printStackTrace();
			out.print("{\"result\":\"false\"}");
		}
	}
	
	/**
	 * 查询用户名是否是检验员
	 * @throws Exception void
	 * @author 张海娜
	 * @date 2013-2-21 下午01:56:10
	 */
	public void findUsersIsjianyan() throws IOException {
		PrintWriter out = getResponse().getWriter();
		try {	
			String loginname = StringUtil.encodingUrl(getRequest().getParameter("loginname"));
			String password = StringUtil.encodingUrl(getRequest().getParameter("password"));
			String md5password = new MD5().getMD5ofStr(password).toLowerCase();
			Users user = userService.findUsersByloginName(loginname);
			if (user!=null){
				if (user.getPsw().equals(md5password)){
					List<Users> lists = userService.findUsersByRoleId(205l);
					for(int i = 0;i<lists.size();i++){
						Users useritem = lists.get(i);
						if (useritem.getLoginname().equals(loginname)){
							out.print(loginname);
							return;
						}
					}
					//否则的话角色错误
					out.print("roleerror");
				}
				else{
					out.print("passworderror");			
				}
			}
			else{
				out.print("loginnameerror");	
			}
							
		} catch (Exception e) {
			e.printStackTrace();
			//-1错误
			out.print("error");
		}
	}
	/**
	 * 
	 *方法描述:查询电子签名
	 *@author: wangxd
	 *@date: 2013-12-11下午04:46:18
	 *@throws IOException
	 */
	public void queryDianziqianming() throws IOException
	{
		setContentType();
		PrintWriter out = getResponse().getWriter();
		String message = "";
		String flag = "";
	  	try {
	  		String loginname = getRequest().getParameter("loginname");
	  		String password = StringUtil.encodingUrl(getRequest().getParameter("password"));
	  		PasswordEncoder md5pass = new Md5PasswordEncoder();
	  		password = md5pass.encodePassword(password,null);
	  		if (loginname != null && !"".equals(loginname)) {
	  			loginname = java.net.URLDecoder.decode(loginname,"UTF-8") ;
			}
	  		Users user = userService.findUsersByloginName(loginname);
			if (user!=null){
				if(password.equals(user.getPsw())){
					if(!"".equals(user.getSignAddress())&&null!=user.getSignAddress())
					{
						message = user.getSignAddress();
						if(message.contains("\\")){
							message = message.replace("\\","/");
						}
						flag = "0";
					}else{
						flag = "3";
						message = user.getUsername();
					}
				}else{
					flag = "1";
				}
			}else{
				flag = "2";
			}
			out.print("{\"ajaxResult\":\""+message+"\",\"flag\":\""+flag+"\"}");
	  	} catch (Exception e) {
	  		flag = "error";
			e.printStackTrace();
			out.print("{\"ajaxResult\":\"error\",\"flag\":\""+flag+"\"}");
		}
	  
	}
	/**
	 * 查询页面上的其他内容
	 * @throws Exception
	 */
	public void queryChooseData() throws Exception {
		try {
			String tableName = this.getRequest().getParameter("tableName");
			String columnName = this.getRequest().getParameter("columnName");
			String [] columns=columnName.split(",");
			
			// 将查询条件保存到Map里
			String[] viewArray = columns;

			Map<String, String> filterMap = getPagerMap();
			filterMap.put("tableName", tableName);
			filterMap.put("columnName", columnName);
			
			// 查询所有的数据
			PageResult result = userService.queryChooseData(filterMap);
			String returnStr = getColumnJson(result, viewArray);
			setContentType();
			PrintWriter out = getResponse().getWriter();
			System.out.println("--!" + returnStr + "--!");
			out.print(returnStr);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 打印图片
	 *  void
	 * @author lishu 
	 */
	public void printImage()
	{
		try
		{
//			String userId = getRequest().getParameter("userId");
//			Users user = userService.findUsersById(Long.parseLong(userId));
			String path = getRequest().getParameter("path");
			String flag = getRequest().getParameter("flag");  //0：前台转码
			String newPath = "";
			if("0".equals(flag)){
				if(!StringUtil.isEmpty(path)){
					newPath =  StringUtil.encodingUrl(path);
				}
			}
			else{
				newPath =  new String(path.getBytes("ISO-8859-1"),"UTF-8");
			}
			//HttpUtil.downImg(ServletActionContext.getResponse(),newPath );
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
	
	public String updatePersonalInfo(){
		   Long userId = Long.parseLong(getUserId());
		  users=userService.findUsersById(userId);
		  SimpleDateFormat df = new SimpleDateFormat("yyyy");//定义格式，不显示毫秒 yyyy-MM-dd 
			Timestamp now = new Timestamp(System.currentTimeMillis());//获取系统当前时间
			String str = df.format(now);
			getRequest().setAttribute("str", str);
		  return SUCCESS;  
	}
	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public Users getUsers() {
		return users;
	}

	public void setUsers(Users users) {
		this.users = users;
	}
 
	public String getOldPsw() {
		return oldPsw;
	}

	public void setOldPsw(String oldPsw) {
		this.oldPsw = oldPsw;
	}
	public String getRoleIdStr() {
		return roleIdStr;
	}
	public void setRoleIdStr(String roleIdStr) {
		this.roleIdStr = roleIdStr;
	}
	public Long getRoleid() {
		return roleid;
	}
	public void setRoleid(Long roleid) {
		this.roleid = roleid;
	}
	public void setOrgId(Long orgId) {
		this.orgId = orgId;
	}
	public int getSuccessFlag() {
		return successFlag;
	}
	public void setSuccessFlag(int successFlag) {
		this.successFlag = successFlag;
	}
	public void setLogService(LogService logService) {
		this.logService = logService;
	}
	public String getUserIds() {
		return userIds;
	}
	public void setUserIds(String userIds) {
		this.userIds = userIds;
	}
	public int getSearchFlag() {
		return searchFlag;
	}
	public void setSearchFlag(int searchFlag) {
		this.searchFlag = searchFlag;
	}
	

	public void setUserId(Long userId) {
		this.userId = userId;
	}

	public String getSidx() {
		return sidx;
	}
	public void setSidx(String sidx) {
		this.sidx = sidx;
	}
	public String getSord() {
		return sord;
	}
	public void setSord(String sord) {
		this.sord = sord;
	}
	public String getOrgNameLabel() {
		return orgNameLabel;
	}
	public void setOrgNameLabel(String orgNameLabel) {
		this.orgNameLabel = orgNameLabel;
	}

	public String getActive() {
		return active;
	}
	public void setActive(String active) {
		this.active = active;
	}
	public String getLoginname() {
		return loginname;
	}
	public void setLoginname(String loginname) {
		this.loginname = loginname;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPsw() {
		return psw;
	}
	public void setPsw(String psw) {
		this.psw = psw;
	}
	public File getUploadImg() {
		return uploadImg;
	}
	public void setUploadImg(File uploadImg) {
		this.uploadImg = uploadImg;
	}
	public String getUploadImgContentType() {
		return uploadImgContentType;
	}
	public void setUploadImgContentType(String uploadImgContentType) {
		this.uploadImgContentType = uploadImgContentType;
	}
	public String getUploadImgFileName() {
		return uploadImgFileName;
	}
	public void setUploadImgFileName(String uploadImgFileName) {
		this.uploadImgFileName = uploadImgFileName;
	}
	public File getUploadSign() {
		return uploadSign;
	}
	public void setUploadSign(File uploadSign) {
		this.uploadSign = uploadSign;
	}
	public String getUploadSignContentType() {
		return uploadSignContentType;
	}
	public void setUploadSignContentType(String uploadSignContentType) {
		this.uploadSignContentType = uploadSignContentType;
	}
	public String getUploadSignFileName() {
		return uploadSignFileName;
	}
	public void setUploadSignFileName(String uploadSignFileName) {
		this.uploadSignFileName = uploadSignFileName;
	}
	public String getSex() {
		return sex;
	}
	public void setSex(String sex) {
		this.sex = sex;
	}
	public String getFixedPhone() {
		return fixedPhone;
	}
	public void setFixedPhone(String fixedPhone) {
		this.fixedPhone = fixedPhone;
	}
	public String getMobile() {
		return mobile;
	}
	public void setMobile(String mobile) {
		this.mobile = mobile;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getUserdesc() {
		return userdesc;
	}
	public void setUserdesc(String userdesc) {
		this.userdesc = userdesc;
	}
	public Long getSecurityClass() {
		return securityClass;
	}
	public void setSecurityClass(Long securityClass) {
		this.securityClass = securityClass;
	}
	public String getCompanyTel() {
		return companyTel;
	}
	public void setCompanyTel(String companyTel) {
		this.companyTel = companyTel;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	
	public ConfigInfo getInfo() {
		return info;
	}
	public void setInfo(ConfigInfo info) {
		this.info = info;
	}
	public void setConfigService(ConfigService configService) {
		this.configService = configService;
	}
	public void setUserRoleService(UserRoleService userRoleService) {
		this.userRoleService = userRoleService;
	}
	public String getJobName() {
		return jobName;
	}
	public void setJobName(String jobName) {
		this.jobName = jobName;
	}
	public File getUploadStamp() {
		return uploadStamp;
	}
	public void setUploadStamp(File uploadStamp) {
		this.uploadStamp = uploadStamp;
	}
	public String getUploadStampContentType() {
		return uploadStampContentType;
	}
	public void setUploadStampContentType(String uploadStampContentType) {
		this.uploadStampContentType = uploadStampContentType;
	}
	public String getUploadStampFileName() {
		return uploadStampFileName;
	}
	public void setUploadStampFileName(String uploadStampFileName) {
		this.uploadStampFileName = uploadStampFileName;
	}
	
	public SysCerify getSysCerify() {
		return sysCerify;
	}
	public void setSysCerify(SysCerify sysCerify) {
		this.sysCerify = sysCerify;
	}
	public String getLockFlag() {
		return lockFlag;
	}
	public void setLockFlag(String lockFlag) {
		this.lockFlag = lockFlag;
	}
	public Organization getOrganization() {
		return organization;
	}
	public void setOrganization(Organization organization) {
		this.organization = organization;
	}
	public Long getOrgId() {
		return orgId;
	}
	public UserRole getUserole() {
		return userole;
	}
	public void setUserole(UserRole userole) {
		this.userole = userole;
	}
	public Long getPosId() {
		return posId;
	}
	public void setPosId(Long posId) {
		this.posId = posId;
	}
	public HSSFSheet getReportDataSheet() {
		return reportDataSheet;
	}
	public void setReportDataSheet(HSSFSheet reportDataSheet) {
		this.reportDataSheet = reportDataSheet;
	}
	public static Log getLog() {
		return log;
	}
	public UserService getUserService() {
		return userService;
	}
	public UserRoleService getUserRoleService() {
		return userRoleService;
	}
	public LogService getLogService() {
		return logService;
	}
	public ConfigService getConfigService() {
		return configService;
	}

	public Timestamp getEntryDate() {
		return entryDate;
	}

	public void setEntryDate(Timestamp entryDate) {
		this.entryDate = entryDate;
	}

	public Long getWorkYears() {
		return workYears;
	}

	public void setWorkYears(Long workYears) {
		this.workYears = workYears;
	}

	public String getYourMajor() {
		return yourMajor;
	}

	public void setYourMajor(String yourMajor) {
		this.yourMajor = yourMajor;
	}

	public Long getAge() {
		return age;
	}

	public void setAge(Long age) {
		this.age = age;
	}

	
	public String getXueliname() {
		return xueliname;
	}

	public void setXueliname(String xueliname) {
		this.xueliname = xueliname;
	}

	public Long getXueliid() {
		return xueliid;
	}

	public void setXueliid(Long xueliid) {
		this.xueliid = xueliid;
	}

	public String getZhichengname() {
		return zhichengname;
	}

	public void setZhichengname(String zhichengname) {
		this.zhichengname = zhichengname;
	}

	public Long getZhichengid() {
		return zhichengid;
	}

	public void setZhichengid(Long zhichengid) {
		this.zhichengid = zhichengid;
	}

	public String getZhiwuname() {
		return zhiwuname;
	}

	public void setZhiwuname(String zhiwuname) {
		this.zhiwuname = zhiwuname;
	}

	public Long getZhiwuid() {
		return zhiwuid;
	}

	public void setZhiwuid(Long zhiwuid) {
		this.zhiwuid = zhiwuid;
	}

	public String getShemidjname() {
		return shemidjname;
	}

	public void setShemidjname(String shemidjname) {
		this.shemidjname = shemidjname;
	}

	public Long getShemidjid() {
		return shemidjid;
	}

	public void setShemidjid(Long shemidjid) {
		this.shemidjid = shemidjid;
	}

	public String getPage() {
		return page;
	}

	public void setPage(String page) {
		this.page = page;
	}

	public String getRows() {
		return rows;
	}

	public void setRows(String rows) {
		this.rows = rows;
	}
	public DbService getDbService() {
		return dbService;
	}
	public void setDbService(DbService dbService) {
		this.dbService = dbService;
	}
    

}
